package Demo;

class Test{
    private int count = 0;
    public synchronized void add(){
        count++;
    }

    public int getCount() {
        return count;
    }
}
public class Demo8 {
    private static Test test = new Test();
    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(() -> {
            for (int i = 0; i < 50000; i++) {
                test.add();
            }
        });
        Thread t2 = new Thread(() -> {
            for (int i = 0; i < 50000; i++) {
                test.add();
            }
        });
        t1.start();
        t2.start();

        t1.join();
        t2.join();
        System.out.println(test.getCount());
    }
}
